home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9818 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.0 KB

  1. Path: hops.cs.jhu.edu!lasher
  2. From: lasher@hops.cs.jhu.edu (John E. Davis)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: goto
  5. Date: 13 Mar 1996 19:45:49 GMT
  6. Organization: JHU computer science
  7. Message-ID: <4i78ld$43f@blaze.cs.jhu.edu>
  8. References: <Pine.OSF.3.91.960313102715.10701D-100000@io.UWinnipeg.ca>
  9. NNTP-Posting-Host: hops.cs.jhu.edu
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Bill Simpson (wsimpson@uwinnipeg.ca) expostulated:
  13. > There was a goto thread lately, and my problem is to state this algorithm 
  14. > cleanly without gotos (which I think is easy, but my attempts have been 
  15. > failures).
  16.  
  17. > 0. x=0;
  18. > 1. x+=erand(maxmean);
  19. > 2. if (urand2()>rate(x)/maxrate)
  20. >     goto step 1
  21. > 3. if (x<=XMAX)
  22. >     {
  23. >     setdot(x,y,z);
  24. >     goto step 1
  25. >     }
  26.  
  27. I know I am no expert, but ...
  28.  
  29. for(x=0;;x+=erand(maxmean))
  30. {
  31. if (urand2()>rate(x)/maxrate) continue;
  32. else if(x<=XMAX) setdot(x,y,z);
  33. else break;
  34. }
  35.  
  36. Although this has no limit on the number of times it is looped through 
  37. ... It looks like it would work ... just add some cort of test to see if 
  38. the loop should end.
  39.  
  40. john davis
  41.